#pragma once
#include <atlbase.h>
#include <atlcom.h>
//#include <initguid.h>
#include <UIRibbon.h>


 MIDL_INTERFACE("30bdce1a-1927-4631-8406-87c6ef6cb517")
    IRibbonExplorerView : public IUnknown
    {
    public:
        virtual HRESULT STDMETHODCALLTYPE OnAfterCreateRibbon(HWND hWnd, HINSTANCE hInstance); 
		virtual HRESULT STDMETHODCALLTYPE Destroy();
		virtual HRESULT STDMETHODCALLTYPE GetRibbonHeight(UINT32 *pHeight);
		virtual HRESULT STDMETHODCALLTYPE SetUIFramework(IUIFramework *pUIFramework);
		virtual HRESULT STDMETHODCALLTYPE IsValid(BOOL *pIsValid);
    };
    
class CRibbonView : public CComObjectRootEx<CComMultiThreadModel> , public IUIApplication, public IUICommandHandler, public IRibbonExplorerView
{
protected:
	CComPtr<IUIFramework> m_pUIFramework;

public:
    BEGIN_COM_MAP(CRibbonView)
        COM_INTERFACE_ENTRY(IUIApplication)
		COM_INTERFACE_ENTRY(IUICommandHandler)
    END_COM_MAP()

	STDMETHOD(OnViewChanged)(UINT32 nViewID, __in UI_VIEWTYPE typeID, __in IUnknown* pView, UI_VIEWVERB verb, INT32 uReasonCode);  
    

    STDMETHOD(OnCreateUICommand)(UINT32 nCmdID, __in UI_COMMANDTYPE typeID, __deref_out IUICommandHandler** ppCommandHandler);
    

    STDMETHOD(OnDestroyUICommand)(UINT32 commandId, __in UI_COMMANDTYPE typeID, __in_opt IUICommandHandler* pCommandHandler);

	STDMETHOD(Execute)(UINT nCmdID,
		UI_EXECUTIONVERB verb, 
		__in_opt const PROPERTYKEY* key,
		__in_opt const PROPVARIANT* ppropvarValue,
		__in_opt IUISimplePropertySet* pCommandExecutionProperties);
	
	STDMETHOD(UpdateProperty)(UINT nCmdID,
		__in REFPROPERTYKEY key,
		__in_opt const PROPVARIANT* ppropvarCurrentValue,
		__out PROPVARIANT* ppropvarNewValue);
    
	static HRESULT CreateFromResourceDLL(CComPtr<CRibbonView> pView, HWND hWnd, HINSTANCE hInstance, LPCTSTR szResourceDllName, LPCTSTR LPszResourceName);
	static HRESULT Create(CComPtr<CRibbonView> pView, HWND hWnd, HINSTANCE hInstance, HMODULE hModule, LPCTSTR LPszResourceName);

	STDMETHOD(Destroy)();
	STDMETHOD(GetRibbonHeight)(UINT32 *pHeight);
	STDMETHOD(IsValid)(BOOL *pIsValid) {*pIsValid = (m_pUIFramework != NULL); return S_OK; }

	virtual ~CRibbonView() {}

protected:
	STDMETHOD(SetUIFramework)(IUIFramework *pUIFramework);
	STDMETHOD(OnAfterCreateRibbon)(HWND hWnd, HINSTANCE hInstance) { return S_OK;}
};
